/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tdtest.data;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author sutter
 */
public class DataObject {
	private final List<OnChangedListener> onChangedListeners = new ArrayList<>();
		
	public void addOnChanagedListener(OnChangedListener listener) {
		synchronized(onChangedListeners) {
			this.onChangedListeners.add(listener);
		}
	}
	
	public void removeOnChangedListener(OnChangedListener listener) {
		synchronized(onChangedListeners) {
			this.onChangedListeners.remove(listener);
		}
	}
	
	public void onUpdate() {
		synchronized(onChangedListeners) {
			for(OnChangedListener onChangeListener:onChangedListeners) {
				onChangeListener.onUpdate();
			}
		}
	}
	
	public void onDelete() {
		synchronized(onChangedListeners) {
			for(OnChangedListener onChangeListener:onChangedListeners) {
				onChangeListener.onDelete();
			}
		}
	}
}
